(function() {
	'use strict';

	//var serviceInfo = "<ul class=\"layui-nav layui-nav-tree layui-inline\" lay-filter=\"service-info\" style=\"margin-right: 10px;\">{{# layui.each(d.serviceInfo, function(index, serviceItem){ }}<li class=\"layui-nav-item\"><a href=\"javascript:;\">{{serviceItem.service_name}}</a><dl class=\"layui-nav-child\">{{# layui.each(serviceItem.optionInfo,function(index,optionItem){ }}<dd><a href=\"javascript:;\" itemid='{{optionItem.option_id}}'>{{optionItem.option_name}}</a></dd>{{# }); }}</dl></li>{{# }); }}</ul>";
    var serviceInfo = "<ul class='layui-nav layui-nav-tree layui-inline' lay-filter='service-info'>{{# var id = getUrlParms('id'); layui.each(d.serviceInfo, function(index, serviceItem){ }}{{# if(id == serviceItem.service_id){ }}<li class='layui-nav-item layui-nav-itemed' itemid='{{serviceItem.service_id}}'>{{# }else{ }}<li class='layui-nav-item' itemid='{{serviceItem.service_id}}'>{{# } }}<a href='javascript:;'>{{serviceItem.service_name}}</a><dl class='layui-nav-child'>{{# layui.each(serviceItem.optionInfo,function(index,optionItem){ }}{{# if(id == serviceItem.service_id && 0 == index){ }}<dd class=\"layui-this\">{{# }else{ }}<dd>{{# } }}<a itemid='{{optionItem.option_id}}' href='javascript:;'>{{optionItem.option_name}}</a></dd>{{# }); }}</dl></li>{{# }); }}</ul>";
    //var data = '';
    var id = getUrlParms('id');
    $.ajax({
        url : "/CivilAffairs/option/getOptionsByServiceType",
        type : "post",
        data : {"serviceType":"2"},//惠民资金
        async : false,
        dataType : "json",
        success : function(result) {
            if(checkResult(result)){
                var data = result.data;
                layui.use([ "laytpl"], function() {
                    var laytpl = layui.laytpl;
                    //拼装侧边栏
                    laytpl(serviceInfo).render(data,function (html) {
                        document.getElementById("option-info").innerHTML = html;
                    });
                    layui.use(["element","layer"],function () {
                        var element = layui.element
                            ,layer = layui.layer;
                        //监听导航点击
                        element.on('nav(service-info)', function(elem){
                            //点击根据id获取内容
                            var optionId = elem.attr("itemid");
                            var serviceId = elem.parents("li").attr("itemid");
                            if(isNull(optionId)||isNull(serviceId)){
                                //layer.msg("未获取到要查看的内容,请刷新页面重试");
                                return;
                            }
                            $.ajax({
                                url : "/CivilAffairs/option/getOptionInfo",
                                type : "post",
                                data : {"optionId":optionId,"serviceId":serviceId},
                                async : false,
                                dataType : "json",
                                success : function(result) {
                                    if(checkResult(result)){
                                        $("#content").html(result.data);
                                    }
                                },
                                error : function(result) {
                                    console.log(result.status+","+result.statusMessage);
                                    layer.msg("系统异常,请稍后重试");
                                }
                            });
                        });
                        //点击选中的按钮
                        $("#option-info .layui-this").find("a").click();
                    });
                });
            }
        },
        error : function(result) {
            console.log(result.status+","+result.statusMessage);
            alert("系统异常,请稍后重试");
        }
    });
}());